﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualTournaments.Services.Tournaments
{
    public class TeamStatics: IComparable
    {
        private static List<String> _header = new List<String>(new String[] { "Team", "Points", "Played Matches", "Won Matches", "Draw Matches", "Lost Matches", "Goals For", "Goals Against" });
        private List<String> _statics;
        private int _points;
        private int _goalsDifference;

        private const int WON_POINTS = 3;
        private const int DRAW_POINTS = 1;
        private const int LOST_POINTS = 0;

       
        public TeamStatics(String team, int wonMatches, int drawMatches, int lostMatches, int goalsFor, int goalsAgainst)
        {
            _points = WON_POINTS * wonMatches + DRAW_POINTS * drawMatches + LOST_POINTS * lostMatches;
            _goalsDifference = goalsFor - goalsAgainst;
            _statics = new List<String>();
            _statics.Add(team);
            _statics.Add(_points.ToString());
            _statics.Add ((wonMatches + drawMatches + lostMatches).ToString());
            _statics.Add(wonMatches.ToString());
            _statics.Add(drawMatches.ToString());
            _statics.Add(lostMatches.ToString());
            _statics.Add(goalsFor.ToString());
            _statics.Add(goalsAgainst.ToString());
        }

        public IEnumerable<String> Statics
        {
            get { return _statics; }
        }

        public static IEnumerable<String> Header
        {
            get { return _header; }
        }

        public int CompareTo(object teamStatics)
        {
            TeamStatics otherTeamStatics = (TeamStatics)teamStatics;

            if (_points < otherTeamStatics._points)
                return 1;
            else if (_points > otherTeamStatics._points)
                return -1;
            else if (_goalsDifference < otherTeamStatics._goalsDifference)
                return 1;
            else if (_goalsDifference > otherTeamStatics._goalsDifference)
                return -1;
            else
                return 0;
        }

    }
}
